package com.flk.oauth.vaildatecode.sms;

import com.flk.oauth.security.SecurityProperties;
import com.flk.oauth.vaildatecode.ValidateCode;
import com.flk.oauth.vaildatecode.ValidateCodeGenerator;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * @author xxwy
 * on 2018/8/21 0021
 * todo: 修改手机的生成器
 */
@Slf4j
@Component("smsValidateCodeGenerator")
public class SmsValidateCodeGenerator implements ValidateCodeGenerator {
    @Autowired
    private SecurityProperties securityProperties;


    @Override
    public ValidateCode generate(ServletWebRequest request) {
        long code1 = securityProperties.getCode().getSms().getCode();
        String code = Long.toString(RandomUtils.nextLong(code1, code1 * 10));
        log.info("生成的数字为 " + code);
        return new ValidateCode(code, securityProperties.getCode().getSms().getExpireIn());
    }


}
